package net.magicalcloud.magicalcloud.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import net.magicalcloud.magicalcloud.R;
import net.magicalcloud.magicalcloud.base.BaseViewHolder;
import net.magicalcloud.magicalcloud.entity.Files;
import net.magicalcloud.magicalcloud.listener.OnRecyclerViewListener;

import butterknife.BindView;


import static net.magicalcloud.magicalcloud.util.ImageLoaderUtil.displayImage;
import static net.magicalcloud.magicalcloud.util.ImageLoaderUtil.getPhotoImageOption;
import static net.magicalcloud.magicalcloud.util.MyUtil.createVideoThumbnail;

/**
 * 各种文件类型的viewholder
 * Created by Pei on 2018/6/8.
 */

public class FileViewHolder extends BaseViewHolder {

    @BindView(R.id.tv_name)
    TextView textViewName;
    @BindView(R.id.iv_type)
    ImageView imageViewType;


    public FileViewHolder(Context context, ViewGroup root, OnRecyclerViewListener listener) {
        super(context, root, R.layout.item_file, listener);
    }

    @Override
    public void bindData(Object o) {
        Files file=(Files)o;
        textViewName.setText(((Files) o).getFileName());
        if(file.getFiletypeId()==5){
            imageViewType.setImageResource(R.drawable.folder);
        }
        else if(file.getFiletypeId()==9){
            //imageViewType.setImageBitmap(createVideoThumbnail(file.getUrl(),100,100));
            imageViewType.setImageResource(R.drawable.video);
        }
        else if(file.getFiletypeId()==6){
            imageViewType.setImageResource(R.drawable.document);
        }
        else if(file.getFiletypeId()==8){
            imageViewType.setImageResource(R.drawable.music);
        }
        else if(file.getFiletypeId()==7){
            displayImage(context,imageViewType,file.getUrl(),getPhotoImageOption());
        }
        else if(file.getFiletypeId()==15){
            imageViewType.setImageResource(R.drawable.others);
        }
    }
}
